﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Linq.Expressions;
using Newtonsoft.Json.Linq;

using CanDoo;
using CanDoo.Core;
using CanDoo.Data;
using CanDoo.Web;
using CanDoo.FineUI;
using CanDoo.Extensions;
using CanDoo.Oil.Core.Models;
using CanDoo.Oil.Core.Contracts;
using CanDoo.Admin.Core.Contracts;
using CanDoo.Admin.Core.Models;
using CanDoo.Secutiry;
using FineUIPro;

namespace CanDoo.Oil.WebApp.Update
{
    public partial class ForUser :PageBase
    {

        public ICustomerContract CustomerContract { get; set; }
        public IUserContract UserContract { get; set; }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                var AddList = new List<User>();

                DB.KeepReading(() =>
                {
                    var cusList = CustomerContract.Entities.ToList();
                    var userList = UserContract.Entities.ToList();
                    foreach (var m in cusList)
                    {
                        var n = userList.FirstOrDefault(p => p.Id == m.Id);
                        if (n == null)
                        {
                            var mEntity = new User();
                            mEntity.Id = m.Id;
                            mEntity.Enable = true;
                            mEntity.UserType = 1;


                            mEntity.UserName = m.CardNo;
                            mEntity.Name = m.Name;
                                mEntity.PasswordHash = PasswordHasher.HashPassword("888888");
                            AddList.Add(mEntity);
                        }
                    }
                });
                UserContract.AddEntity(AddList);
                Response.Write(AddList.Count.ToString());
            }
        }
    }
}